﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace Summerset.Isbndb
{
    /// <summary>
    /// Base class for all response elements returned as part of a ResponsePageBase
    /// </summary>
    public abstract class ResponseElementChildBase
    {

        /// <summary>
        /// The element that contains the underlying data for this instance.
        /// </summary>
        protected readonly XmlElement _element;

        /// <summary>
        /// Initializes a new instance of <see cref="ResponseElementChildBase"/>.
        /// If the provided element argument's name does not match the ExpectedElementName property, an exception
        /// will be thrown.
        /// </summary>
        /// <param name="element">The element containing the underlying data for this instance.</param>
        /// <exception cref="ArgumentException">Thrown if the element argument's name does not match the ExpectedElementName property.</exception>
        public ResponseElementChildBase(XmlElement element)
        {
            // validate we received a proper element name
            if (ExpectedElementName != element.Name)
                throw new ArgumentException(string.Format("Element name '{0}' did not match expected name {1}", element.Name, ExpectedElementName));
            
            _element = element;
        }

        /// <summary>
        /// Gets the xml element name that's expected by this class's constructor.
        /// </summary>
        protected abstract string ExpectedElementName { get; }
    }
}
